package com.hns.can.mainte.web;

import java.net.URLEncoder;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.service.ReportCarMaintePlanService;
import com.hns.can.mainte.vo.MaintenanceParamVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;

/**
 * 维保计划
 * @author:yecb
 * @email:lps00@163.com
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/reportCarMaintePlan")
public class ReportCarMaintePlanController extends BaseController  {
	private final static  String[] headerNames = {"车牌号", "当前运行里程", "上次维保日期", "上次维保里程", "计划维保类别", "计划维保里程", "剩余里程", "计划维保日期", "剩余天数","计划更换零部件"};
	private final static String[] headerFields = {"licPltNo", "totalMile", "lastMaintenDate", "lastMaintenMile", "maintenCgy","planMile", "remainMile", "planMaintenDate", "remainTime", "partsCode"};
    @Autowired
    private ReportCarMaintePlanService reportCarMaintePlanService;
    
    /**
     * 查询维保计划(分页返回)
     * @param conditionVo
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/getMaintenancePlanPage")
    @ResponseBody
    public Object getMaintenancePlanPage(MaintenanceParamVo conditionVo) throws Exception {
    	SysUserEntity sysUserEntity=getCurrentUser().getUser();
    	conditionVo.setCorpId(sysUserEntity.getCorpId());
        Pagination page = reportCarMaintePlanService.searchMaintenancePage(conditionVo);
        GridPage grid = new GridPage(page);
        return getReturnResult(grid);
    }
    
    /**
     * 查询维保计划
     * @param conditionVo
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @RequestMapping("/getMaintenancePlanList")
    @ResponseBody
    public Object getMaintenancePlanList(MaintenanceParamVo conditionVo) throws Exception {
    	SysUserEntity sysUserEntity=getCurrentUser().getUser();
    	conditionVo.setCorpId(sysUserEntity.getCorpId());
        List list= reportCarMaintePlanService.searchMaintenanceList(conditionVo);
        return getReturnResult(list);
    }
    
    /**
     * 导出维保计划的Excel文件
     * @param conditionVo
     * @param response
     * @throws Exception
     * @author:yecb
     * @email:lps00@163.com
     */
    @SuppressWarnings("unchecked")
	@RequestMapping("exportMaintenancePlanExcel")
    public void exportMaintenancePlanExcel(MaintenanceParamVo conditionVo,HttpServletResponse response) throws Exception {
    	SysUserEntity sysUserEntity=getCurrentUser().getUser();
    	conditionVo.setCorpId(sysUserEntity.getCorpId());
        List<BaseEntity> list = reportCarMaintePlanService.searchMaintenanceList(conditionVo);        
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", URLEncoder.encode("维保计划数据", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "维保计划数据");
    }
    
   /**
    * 导出维保计划的PDF文件
    * @param params
    * @param response
    * @throws Exception
    * @author:yecb
    * @email:lps00@163.com
    */
    @SuppressWarnings("unchecked")
	@RequestMapping("exportMaintenancePlanPdf")
    public void exportMaintenancePlanPdf(MaintenanceParamVo conditionVo,HttpServletResponse response) throws Exception {
    	SysUserEntity sysUserEntity=getCurrentUser().getUser();
    	conditionVo.setCorpId(sysUserEntity.getCorpId());
        List<BaseEntity> list = reportCarMaintePlanService.searchMaintenanceList(conditionVo);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", URLEncoder.encode("维保计划数据", "UTF-8")+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "维保计划数据");
    }
  
}
